package solutions.leetcode.easy;

import solutions.lib.BaseSolution;

import java.util.Arrays;
import java.util.OptionalInt;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/minimum-moves-to-equal-array-elements/">453. 最小操作次数使数组元素相等</a>
 */
public class Solution453 extends BaseSolution {

    public int minMoves(int[] nums) {
        OptionalInt t = Arrays.stream(nums).min();
        int min = Integer.MIN_VALUE;
        if (t.isPresent()) {
            min = t.getAsInt();
        }

        int rst = 0;
        for (int v : nums) {
            rst += v - min;
        }
        return rst;
    }

    public static void main(String[] args) {
        Solution453 solution = new Solution453();
        System.out.println(solution.minMoves(new int[] {
                -100,0,100
        }));
    }
}